package mybatis;

import org.apache.ibatis.annotations.*;

import java.util.List;

public interface UserMapper {

    @Results(id = "userMap", value = {
            @Result(property = "id", column = "id", id = true),
            @Result(property = "name", column = "name")
    })
    @Select("select id,name from t_user where id=#{id}")
    User selectNameById(@Param("id") Integer id);


    @ResultMap("userMap")
    @Select("select id,name from t_user where id=#{id}")
    User selectById(@Param("id") Integer id);




    @Insert("insert into t_user(id,name) values(#{user.id},#{user.name})")
    Integer insert(@Param("user") User user);



    @Insert("insert into t_user(name) values(#{user.name})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    Integer insertForId(@Param("user") User user);



    @Update("update t_user set name=#{user.name} where id=#{user.id}")
    Integer update(@Param("user") User user);

    @Update("delete from t_user where id=#{id}")
    Integer delete(@Param("id") Integer id);



    @SelectProvider(type = UserProvider.class, method = "selectList")
    List<User> selectList();

}


